package com.derbysoft.ota.application.translator.rs;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.interfaces.protocol._2009a.ErrorType;
import com.derbysoft.ota.interfaces.protocol._2009a.ErrorsType;
import com.derbysoft.remote.dswitch.core.ErrorDTO;
import com.derbysoft.remote.dswitch.core.ErrorsDTO;

public class ErrorsTranslator implements Translator<ErrorsDTO, ErrorsType> {
	
//    private static final String ERROR_TYPE_UNKNOWN = "1";

    @Override
    public ErrorsType translate(ErrorsDTO source) {
        ErrorsType errorsType = new ErrorsType();
        for (ErrorDTO errorDTO : source.getErrorList()) {
            errorsType.getError().add(convertErrorType(errorDTO));
        }
        return errorsType;
    }

    private ErrorType convertErrorType(ErrorDTO errorDTO) {
        ErrorType errorType = new ErrorType();
        //TODO set type accordingly
//        errorType.setType(ERROR_TYPE_UNKNOWN);
        errorType.setValue(errorDTO.getMessage());
        return errorType;
    }
}
